/*
 * @Description:
 * @Author: Zzt
 * @Date: 2022-11-10 16:49:18
 * @LastEditTime: 2023-01-05 17:47:31
 */
import { createContext, useReducer, useEffect, useContext } from 'react';
import { SET_CHART_DATA, SET_TABLE_DATA } from '../constants';
import { systemForTable, systemForStat } from '@/api/statistics/statistics';
import { SystemConfigurationReducer } from '../reducers/SystemConfigurationReducer';
const initialState = {
  dataList: [],
  chartList: []
};
const SystemConfigurationContext = createContext();
const SystemConfigurationContextProvider = (props) => {
  const [state, dispatch] = useReducer(SystemConfigurationReducer, initialState);
  const actions = {
    setChartData(data) {
      systemForStat({ ...data, menuType: 1 }).then((res) => {
        const { data } = res;
        dispatch({ type: SET_CHART_DATA, data });
      });
    },
    setTableData(data) {
      systemForTable({ ...data }).then((res) => {
        const { data } = res;
        console.log('datadata', data);
        dispatch({ type: SET_TABLE_DATA, data });
      });
    }
  };
  useEffect(() => {}, []);
  return (
    <SystemConfigurationContext.Provider value={{ ...state, ...actions }}>
      {props.children}
    </SystemConfigurationContext.Provider>
  );
};
export const useSystemConfigurationContext = () => {
  return useContext(SystemConfigurationContext);
};
export { SystemConfigurationContext, SystemConfigurationContextProvider };
